package com.xiaotu.threadMethod;

/**
 * @Author xiaotu
 * @Description //TODO
 * @Date 2022/3/25 16:53
 * @ClassName TestPriority
 * @Version 1.0
 * 优先级测试
 * 但最终决定权在CPU,只是通过1~10配比,权重就会变化
 **/
public class TestPriority {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()+"的优先级====>"+Thread.currentThread().getPriority());
        MyPriority myPriority = new MyPriority();
        Thread thread1 = new Thread(myPriority, "线程一");
        Thread thread2 = new Thread(myPriority, "线程二");
        Thread thread3 = new Thread(myPriority, "线程三");
        //thread1.setPriority(10);
        //thread2.setPriority(5);
        //thread3.setPriority(1);
        thread1.start();
        thread2.start();
        thread3.start();
        /**
         * 运行结果{
         *     设置前:   线程三的优先级====>5
         *              线程一的优先级====>5
         *              线程二的优先级====>5
         *
         *
         *     设置后:   线程一的优先级====>10
         *              线程二的优先级====>5
         *              线程三的优先级====>1
         * }
         */

    }
}

class MyPriority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"的优先级====>"+Thread.currentThread().getPriority());
    }
}
